import type { TableColumnData } from '@arco-design/web-vue'

import { useSearchUser } from '@/apis/user/composables'
import { Role } from '@/constants/role'

export function useStudentTable() {
  const { data, isLoading } = useSearchUser({ role: Role.Student })

  return {
    isLoading,
    columns: [
      {
        title: '学号/工号',
        dataIndex: 'username',
        width: 150,
        align: 'center',
        sortable: {
          sortDirections: ['ascend', 'descend']
        }
      },
      {
        title: '姓名',
        dataIndex: 'name',
        width: 150
      },
      {
        title: '权限',
        dataIndex: 'role',
        slotName: 'role'
      },
      {
        title: '操作',
        slotName: 'action',
        width: 80,
        align: 'center',
        fixed: 'right'
      }
    ] as const satisfies TableColumnData[],
    students: data as Readonly<typeof data>
  }
}
